<html>
<head>
<style>
  .ace_editor {
    border: 0;
    width: auto;
    height: 100%;
    margin: 0;
    top:0;
    right:0;
    bottom:0;
    left:0;
    z-index: 10000;
    touch-action: none;
  }

  body {
    padding: 0px;
    margin: 0px;
    overflow: hidden;
    -ms-overflow-style: scrollbar;
  }
</style>
</head>
<body>
<textarea id="source">package com.sencha.gxt.explorer.client.window;

import static com.sencha.gxt.core.client.Style.Anchor.CENTER;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gxt.core.client.Style.AnchorAlignment;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.core.client.resources.ThemeStyles;
import com.sencha.gxt.data.shared.IconProvider;
import com.sencha.gxt.data.shared.TreeStore;
import com.sencha.gxt.examples.resources.client.ExampleStyles;
import com.sencha.gxt.examples.resources.client.TestData;
import com.sencha.gxt.examples.resources.client.Utils;
import com.sencha.gxt.examples.resources.client.Utils.Theme;
import com.sencha.gxt.examples.resources.client.images.ExampleImages;
import com.sencha.gxt.examples.resources.client.model.NameImageModel;
import com.sencha.gxt.explorer.client.app.ui.ExampleContainer;
import com.sencha.gxt.explorer.client.model.Example.Detail;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.Window;
import com.sencha.gxt.widget.core.client.container.AccordionLayoutContainer;
import com.sencha.gxt.widget.core.client.container.AccordionLayoutContainer.AccordionLayoutAppearance;
import com.sencha.gxt.widget.core.client.container.AccordionLayoutContainer.ExpandMode;
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
import com.sencha.gxt.widget.core.client.tree.Tree;

public class AccordionWindowExample implements IsWidget, EntryPoint {

  protected static final int PREFERRED_WIDTH = 1;
  protected static final int PREFERRED_HEIGHT = 1;
  // keep margins for window shadow
  protected static final int PREFERRED_MARGIN = 2;

  private SimpleContainer container;
  private Window window;

  @Override
  public Widget asWidget() {
    if (container == null) {
      AccordionLayoutAppearance appearance = GWT.<AccordionLayoutAppearance> create(AccordionLayoutAppearance.class);

      final NameImageModel modelFamily = newItem("Family", null);
      final NameImageModel modelFriends = newItem("Friends", null);

      TreeStore<NameImageModel> store = new TreeStore<NameImageModel>(NameImageModel.KP);
      store.add(modelFamily);
      store.add(modelFamily, newItem("John", "user"));
      store.add(modelFamily, newItem("Olivia", "user-girl"));
      store.add(modelFamily, newItem("Noah", "user-kid"));
      store.add(modelFamily, newItem("Emma", "user-kid"));
      store.add(modelFamily, newItem("Liam", "user-kid"));
      store.add(modelFriends);
      store.add(modelFriends, newItem("Mason", "user"));
      store.add(modelFriends, newItem("Sophia", "user-girl"));
      store.add(modelFriends, newItem("Isabella", "user-girl"));
      store.add(modelFriends, newItem("Jacob", "user"));

      Tree<NameImageModel, String> tree = new Tree<NameImageModel, String>(store,
          new ValueProvider<NameImageModel, String>() {
            @Override
            public String getValue(NameImageModel object) {
              return object.getName();
            }

            @Override
            public void setValue(NameImageModel object, String value) {
            }

            @Override
            public String getPath() {
              return "name";
            }
          }) {
        @Override
        protected void onAfterFirstAttach() {
          super.onAfterFirstAttach();
          
          setExpanded(modelFamily, true);
          setExpanded(modelFriends, true);
        }
      };
      tree.setIconProvider(new IconProvider<NameImageModel>() {
        public ImageResource getIcon(NameImageModel model) {
          if (null == model.getImage()) {
            return null;
          } else if ("user-girl" == model.getImage()) {
            return ExampleImages.INSTANCE.userFemale();
          } else if ("user-kid" == model.getImage()) {
            return ExampleImages.INSTANCE.userKid();
          } else {
            return ExampleImages.INSTANCE.user();
          }
        }
      });

      ContentPanel cp1 = new ContentPanel(appearance);
      cp1.setHeading("Online Users");
      cp1.add(tree);
      if (Theme.BLUE.isActive() || Theme.GRAY.isActive()) {
        cp1.getHeader().addStyleName(ThemeStyles.get().style().borderTop());
      }

      ContentPanel cp2 = new ContentPanel(appearance);
      cp2.setBodyStyleName(ExampleStyles.get().paddedText());
      cp2.setHeading("Settings");
      cp2.add(new Label(TestData.DUMMY_TEXT_SHORT));

      ContentPanel cp3 = new ContentPanel(appearance);
      cp3.setBodyStyleName(ExampleStyles.get().paddedText());
      cp3.setHeading("Stuff");
      cp3.add(new Label(TestData.DUMMY_TEXT_SHORT));

      ContentPanel cp4 = new ContentPanel(appearance);
      cp4.setBodyStyleName(ExampleStyles.get().paddedText());
      cp4.setHeading("More Stuff");
      cp4.add(new Label(TestData.DUMMY_TEXT_SHORT));

      AccordionLayoutContainer accordion = new AccordionLayoutContainer();
      accordion.setExpandMode(ExpandMode.SINGLE_FILL);
      accordion.add(cp1);
      accordion.add(cp2);
      accordion.add(cp3);
      accordion.add(cp4);
      accordion.setActiveWidget(cp1);

      container = new SimpleContainer() {

        @Override
        public void setVisible(boolean visible) {
          super.setVisible(visible);
          if (visible) {
            window.show();
            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
              @Override
              public void execute() {
                // since this is deferred, check that window is actually visible
                if (window.isVisible()) {
                  window.alignTo(container.getElement(), new AnchorAlignment(CENTER, CENTER), 0, 0);
                }
              }
            });
          } else {
            window.hide();
          }
        }
      };

      window = new Window();
      window.setResizable(false);
      window.setHeading("Accordion Window");
      window.setWidth(275);
      window.setHeight(350);
      window.add(accordion);
      window.setClosable(false);
      window.getDraggable().setContainer(container);
    }
    return container;
  }

  private NameImageModel newItem(String text, String iconStyle) {
    return new NameImageModel(text, iconStyle);
  }

  @Override
  public void onModuleLoad() {
    new ExampleContainer(this)
            .setPreferredWidth(PREFERRED_WIDTH)
            .setPreferredHeight(PREFERRED_HEIGHT)
            .setPreferredMargin(PREFERRED_MARGIN)
        .doStandalone();
  }

}
</textarea>

<script src="../../samples/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
  var type = "{type}";
  if (type == ("{" + "type}")) {
    // something went wrong, use java as default
    type = "java";
  }
  var editor = ace.edit("source");
  var mode = "ace/mode/" + type;
  var theme = "ace/theme/chrome";
  var readOnly = true;
  editor.getSession().setMode(mode);
  editor.getSession().setUseWorker(false);
  editor.setTheme(theme);
  editor.setShowPrintMargin(false);
  editor.renderer.setShowGutter(true);
  editor.setHighlightActiveLine(false);
  editor.setDisplayIndentGuides(true);
  editor.setReadOnly(readOnly);
  editor.renderer.setPadding(10);
  editor.renderer.setScrollMargin(10, 10, 0, 0);
  editor.getSession().setOptions({
    tabSize: 8,
    useSoftTabs: true,
    useWrapMode: false,
  });
</script>
</body>
</html>